package com.meter.config.service.impl;

import java.util.Arrays;
import java.util.List;
import com.meter.common.enums.DataSourceType;
import com.meter.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meter.common.annotation.DataSource;
import org.springframework.stereotype.Service;
import com.meter.config.mapper.ConfigAlarmMapper;
import com.meter.config.domain.ConfigAlarm;
import com.meter.config.service.IConfigAlarmService;
import com.meter.common.core.text.Convert;

/**
 * 告警配置Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-15
 */
@Service
public class ConfigAlarmServiceImpl extends ServiceImpl<ConfigAlarmMapper, ConfigAlarm> implements IConfigAlarmService
{

    /**
     * 查询告警配置
     * 
     * @param alarmId 告警配置主键
     * @return 告警配置
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public ConfigAlarm selectConfigAlarmByAlarmId(Long alarmId)
    {
        return baseMapper.selectConfigAlarmByAlarmId(alarmId);
    }

    /**
     * 查询告警配置列表
     * 
     * @param configAlarm 告警配置
     * @return 告警配置
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<ConfigAlarm> selectConfigAlarmList(ConfigAlarm configAlarm)
    {
        return baseMapper.selectConfigAlarmList(configAlarm);
    }

    /**
     * 新增告警配置
     * 
     * @param configAlarm 告警配置
     * @return 结果
     */
    @Override
    public int insertConfigAlarm(ConfigAlarm configAlarm)
    {
        configAlarm.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insert(configAlarm);
    }

    /**
     * 修改告警配置
     * 
     * @param configAlarm 告警配置
     * @return 结果
     */
    @Override
    public int updateConfigAlarm(ConfigAlarm configAlarm)
    {
        configAlarm.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateById(configAlarm);
    }

    /**
     * 批量删除告警配置
     * 
     * @param alarmIds 需要删除的告警配置主键
     * @return 结果
     */
    @Override
    public int deleteConfigAlarmByAlarmIds(String alarmIds)
    {
        return baseMapper.deleteBatchIds(Arrays.asList(Convert.toLongArray(alarmIds)));
    }

    /**
     * 删除告警配置信息
     * 
     * @param alarmId 告警配置主键
     * @return 结果
     */
    @Override
    public int deleteConfigAlarmByAlarmId(Long alarmId)
    {
        return baseMapper.deleteById(alarmId);
    }
}
